//
//  ZYStatusBottomView.swift
//  WBBeta1
//
//  Created by wustzhy on 16/8/14.
//  Copyright © 2016年 Yestin. All rights reserved.
//

import UIKit

class ZYStatusBottomView: UIView {
    
    var retweetButton:UIButton?
    var commentButton:UIButton?
    var unlikeButton:UIButton?
    
    var statusViewModel:ZYStatusViewModel?{
        didSet{
            retweetButton?.setTitle(statusViewModel?.repostsCountStr, forState: UIControlState.Normal)
            commentButton?.setTitle(statusViewModel?.commentsCountStr, forState: UIControlState.Normal)
            unlikeButton?.setTitle(statusViewModel?.attitudesCountStr, forState: UIControlState.Normal)
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame:frame)
        serupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func serupUI(){
        backgroundColor = UIColor.whiteColor()
        // 添加控件
        retweetButton = addChildButton("timeline_icon_retweet", title: "转发")
        commentButton = addChildButton("timeline_icon_comment", title: "评论")
        unlikeButton = addChildButton("timeline_icon_unlike", title: "赞")
        let line1 = addChildLine()
        let line2 = addChildLine()
        // 设置约束
        retweetButton!.snp_makeConstraints { (make) -> Void in
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commentButton!)
        }
        commentButton!.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetButton!.snp_trailing)
            make.width.equalTo(unlikeButton!)
        }
        unlikeButton!.snp_makeConstraints { (make) -> Void in
            make.top.trailing.bottom.equalTo(self)
            make.leading.equalTo(commentButton!.snp_trailing)
        }
        
        line1.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self)
            make.centerX.equalTo(retweetButton!.snp_trailing)
        }
        line2.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self)
            make.centerX.equalTo(commentButton!.snp_trailing)
        }

    }

    
    
    func addChildButton(imgName: String, title: String) -> UIButton{
        let button = UIButton()
        // 背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        // 设置image
        button.setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        button.setTitle(title, forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        // 添加按钮
        addSubview(button)
        button.userInteractionEnabled = true
        
        return button
    }

    func addChildLine() -> UIImageView{
        let img = UIImageView(imgName: "timeline_card_bottom_line")
        // 添加
        addSubview(img)
        return img
    }

    
    
    
    
}
